package com.wzw.springboot.principle.use.batch.simple;

import lombok.extern.slf4j.Slf4j;
import org.springframework.batch.core.listener.ItemListenerSupport;

import java.util.List;

/**
 * 处理过程的监听器，ItemListenerSupport集成了 ItemReadListener、ItemProcessListener、ItemWriteListener
 *
 * @author Wangzhiwen
 */
@Slf4j
@SuppressWarnings("ALL")
public class PersonListenerSuppor extends ItemListenerSupport<Person, Person> {

    public PersonListenerSuppor() {
        super();
    }

    @Override
    public void afterRead(Person item) {
        log.info("After Read Person {}", item);
    }

    @Override
    public void beforeRead() {
        log.info("Before Read Person");
    }

    @Override
    public void onReadError(Exception ex) {
        log.error("On Read Error", ex);
    }

    @Override
    public void afterProcess(Person item, Person result) {
        log.info("After Process {} , {}", item, result);
    }

    @Override
    public void beforeProcess(Person item) {
        log.info("Before Process {}", item);
    }

    @Override
    public void onProcessError(Person item, Exception e) {
        log.error("Process Error", e);
    }

    @Override
    public void afterWrite(List<? extends Person> item) {
        log.info("After Write");
    }

    @Override
    public void beforeWrite(List<? extends Person> item) {
        log.info("Before Write");
    }

    @Override
    public void onWriteError(Exception ex, List<? extends Person> item) {
        log.error("Write Error", ex);
    }
}
